/**
 * 
 *  Code contributed by IUP Research Institute
 * 
 *     This file is part of NetworkMon.
 *
 *   NetworkMon is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; version 2 of the License.
 *
 *   NetworkMon is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with NetworkMon; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package networkbackend;

/**
 * 
 * @author fkern
 */
public class PacketNode implements Comparable<Object> {

	public String sourceAddress;
	public String destinationAddress;
	public int sourcePort;
	public int destinationPort;
	public int protocol;
	public int length;
	public String sendersName;
	public String recName;
	public java.util.Date timeStamp;

	public boolean isSent;

	public String getListLabel() {

		return destinationAddress + ":" + Integer.toString(destinationPort);

	}

	/** Creates a new instance of PacketNode */
	public PacketNode(String src, String dest, int srcPort, int destPort,
			int prot, int len, String sendN, String recN) {

		sourceAddress = src;
		destinationAddress = dest;
		sourcePort = srcPort;
		destinationPort = destPort;
		protocol = prot;
		length = len;
		sendersName = sendN;
		recName = recN;
		timeStamp = new java.util.Date();

	}

	public PacketNode() {

	}

	public int compareTo(Object obj) {
		int retval = 0;
		PacketNode p = (PacketNode) obj;

		// return less < 0 if this < obj
		// return > 0 if this > obj
		// return 0 if =

		if (this.sendersName.compareTo(p.sendersName) == 0) {
			retval = 0;
		}
		// else if (this.sourceAddress.compareTo(p.sourceAddress) == 0)
		// {
		// retval = 0;
		// }
		// else if (this.destinationAddress.compareTo(p.sourceAddress) == 0)
		// {
		// retval = 0;
		// }
		// else if (this.sourceAddress.compareTo(p.destinationAddress) == 0)
		// {
		// retval = 0;
		// }
		else if (this.sendersName.compareTo(p.sendersName) > 0) {
			retval = 1;
		} else if (this.sendersName.compareTo(p.sendersName) < 0) {
			retval = -1;
		}

		return retval;
	}
}
